package Service.Impl;

import Dao.Impl.MainTypeDaoImpl;
import Dao.MainTypeDao;
import Domain.MainType;
import Domain.Product;
import Service.MainTypeService;
import Service.ProductService;

import javax.swing.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MainTypeServiceImpl implements MainTypeService {
    private MainTypeDao dao = new MainTypeDaoImpl();
    @Override
    public List<MainType> FindALLMainType() {
        return dao.FindALLMainType();
    }

    @Override
    public HashMap<String, List<Product>> FindIndexItem() {
        MainTypeService service = new MainTypeServiceImpl();
        List<MainType> list = service.FindALLMainType();

        Map<String,List<Product>> map = new HashMap<>();

        for (MainType type : list) {
            ProductService service1 = new ProductServiceImpl();
            List<Product> product = service1.FindProductByTypeid(type.getId());

            map.put(type.getPname(),product);
        }
        return (HashMap<String, List<Product>>) map;
    }
}
